package cn.sinjet.viewmodel;

import java.util.concurrent.ConcurrentHashMap;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import cn.sinjet.sinjetui.data.PropBase;

public class ViewPropertyCenter {
	protected ConcurrentHashMap<Integer, PropBase> mMapIdValue = new ConcurrentHashMap<Integer, PropBase>();
//	private HashMap<String, Integer> objDataMap = new HashMap<String, Integer>();
//	private Context mContext;	
	public ViewPropertyCenter() {
//		mContext = context;
//		loadObjDataFromXML();
	}

	public void handleSetViewProp(Bundle data) {
		int viewId = data.getInt("id");
		if(-1 == viewId)  return;
		PropBase prop = null;
		if(mMapIdValue.containsKey(viewId))
		     prop  = mMapIdValue.get(viewId);
		else {
			prop = ViewDefine.newPropById(viewId);
			mMapIdValue.put(viewId, prop);
		}
		if(prop != null){
			prop.storeProperty(data);
		}else{
			Log.d("ui","can't find view id:"+viewId);
		}
	}

	
	public void restoreUIProperty(View view) {
		Log.d("debug","restoreUIProperty:"+view.getId());
		if (view == null) return;
		int viewId = view.getId();
		if(viewId == -1) return;
		if (!mMapIdValue.containsKey(viewId))  return;
		
		PropBase dataObj = mMapIdValue.get(viewId);
		if(dataObj != null){
			dataObj.restoreProperty(view);
		}else{
			Log.d("ui","Can't find viewId:"+viewId);
		}
	}
}
